#!/usr/bin/perl -w

use strict;
use warnings;
use utf8;
use open ':encoding(utf8)';
use lib '../';
use ImportHelpers;

#@todo We need to not pass in 

my $sourceDir = ImportHelpers::getSourceDirName(__FILE__);

ImportHelpers::insertWork(
	language  => 'grc',
	osis_id   => 'MorphGNT+UBS4',
	name      => "MorphGNT with UBS4",
	type      => 'manuscript-edition',
	copyright => "By <a href='http://ccat.sas.upenn.edu/'><abbr title='Center for Computer Analysis of Texts'>CCAT</abbr></a> and <a href='http://jtauber.com/morphgnt/'>James Tauber</a>.", #todo
	url       => ImportHelpers::getSourceExternalURL($sourceDir),
	licenses  => [qw( http://creativecommons.org/licenses/by-nc-sa/3.0/ )]
);

my $datafile = "ccat-tauber-morphgnt-v5_08-utf8.txt";
open IN, "$sourceDir/$datafile" or die "Dir $datafile doesn't exist.";

my $lastVerse = 0;
while(<IN>){
	#next if !/^2[345]/; #is 123 John: temp
	next if not s/^(\d\d)(\d\d)(\d\d) (\S\S \S+) //;
	my $book = $ImportHelpers::osisNewTestamentCodes[$1-1];
	next if !ImportHelpers::isBookOK($book);
	my $chapter = $2;
	my $verse = $3;
	my $parsing = $4;
	
	s/ (\S+)?$//;
	my $lemma = $1;
	s/\r?\n$//; #xp-chomp
	my $word = $_;
	
	my %args = (
		data => $word,
		type => 'word',
		
		book => $book,
		chapter => $chapter,
		verse => $verse,
		
		parsing => $parsing,
		lemma => $lemma
	);
	
	#MorphGNT has some weirdness about how the variant ending is handled. It has verse 9 twice in two places
	# So replace erroneous verse 9 with verse 20
	#if($book eq 'Mark' && $chapter == 16 && $verse == 9 && $lastVerse == 20){
	#	$args{verse} = $lastVerse;
	#}
	#else {	
	#	$lastVerse = $verse;
	#}

	ImportHelpers::insertToken(%args);
	
}
ImportHelpers::finishBookRefs();
close IN;

1;